Quiz I:
Date: Tuesday Feb. 10
Material: Chapter 1 + Chapter 2 (Up to and including Scanner)
Where: during class time
Format: MCQ + TF (Quiz) and Coding problem (Classwork)

- Chapter 3: built-in Java classes

1) Object creation
Scanner: interactive programs
Scanner scan = new Scanner(System.in);
We create a scan object from the class called Scanner (java.util.Scanner)

scan.nextLine() ---> String
scan.nextDouble() ---> double
scan.nextInt() ---> int

int val = scan.nextDouble(); // Compile-time error
int val = scan.nextInt(); // valid
String val = scan.nextInt() + ""; // valid 

1 + "" ---> "1"

a vs a()

System.out.print()

int val = 12;
val is said to be a primitive variable
val: 12

String name = new String("Iron Man");
name is said to be an object reference variable

name: add1  ----> add1: Iron Man

Example#1: StringDemo.java

int length(): method header or signature


2) Effect of assignment on objects

int val1 = 5, val2 = 6;

System.out.println("Val1: " + val1 + ", val2: " + val2); 

val1: 5		val2: 6

val1 = val2;

val1: 6		val2: 6
System.out.println("Val1: " + val1 + ", val2: " + val2); 


We end up with two different locations with the same value of 6


String str1 = "Iron Man";
String str2 = "James Bond";


str1: add1 ---> add1: "Iron Man"
str2: add2 ---> add2: "James Bond"

str1 = str2;

str1: add2 ---> "James Bond" <--- add2 :str2
System.gc(); // It is not advisable

System.out.println(str1.length()); // 10
System.out.println(str2.length()); // 10

3) String

charAt
length
substring
concat
toLowerCase
toUpperCase
equals
equalsIgnoreCase
compareTo
replace
indexOf
trim

Example#2: StringMethods.java

Aside:

Wissam: idx of W is 0

'a' + 'b' ---> 195; Fix: "" + 'a' + 'b' 







